<template>
  <div>
    <el-form ref="myform" :model="formItem" class="form-view" label-width="100px" size="mini">
      <el-row :gutter="40">
        <el-col :span="24">
          <el-form-item label="组长审批结果" prop="approvalComments">
            {{ formItem.agree }}
          </el-form-item>
          <el-form-item label="组长审批意见" prop="approvalComments">
            {{ formItem.approvalComments }}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { leaderApprovalDetail as detail } from '@neu/dcam-ui/api/spareconsume'
const formItem = {
  // 工作流TaskId
  taskId: '',
  // 工单号
  workNum: '',
  // 审批意见
  approvalComments: '',
  // 操作人编码
  operatorCode: '',
  // 操作人姓名
  operatorName: '',
  // 是否同意
  whetherAgree: null,

  agree: ''
}
const formRules = {
  approvalComments: [{ required: true, message: '审批意见不能为空', trigger: 'blur' }]
}
export default {
  props: {
    taskId: {
      required: false,
      type: String,
      default: 'NULL'
    },
    workOrderNum: {
      required: false,
      type: String,
      default: ''
    }
  },
  data() {
    return {
      // 编辑的表单内容
      formItem: {
        ...formItem
      },
      // 表单验证规则
      rules: { ...formRules }
    }
  },
  created() {
    this.fetch()
  },
  methods: {
    fetch() {
      if (this.workOrderNum !== 'NULL') {
        detail(this.workOrderNum, this.taskId).then(response => {
          this.formItem = {
            ...response.data
          }
          if (this.formItem.whetherAgree === true) {
            this.formItem.agree = '通过'
          } else {
            this.formItem.agree = ''
          }
        })
      } else {
        this.formItem = {
          ...formItem
        }
        if (this.formItem.whetherAgree === true) {
          this.formItem.agree = '通过'
        } else {
          this.formItem.agree = ''
        }
      }
    }
  }
}
</script>

